package cn.afactory.tygz.ui.base.entity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Kenneth on 15/9/13.
 */
public class LoganHotWordEntity {
    private static final long serialVersionUID = 9000803117055580328L;
    /**
     * 热词内容
     */
    public String content;

    /**
     * 热词权重
     */
    public long qz;

    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static LoganHotWordEntity deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static LoganHotWordEntity deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            LoganHotWordEntity result = new LoganHotWordEntity();

            // 热词内容

            if(!json.isNull("content")){
                result.content = json.optString("content", null);
            }
            // 热词权重
            result.qz = json.optLong("qz");
            return result;
        }
        return null;
    }

    /*
     * 序列化函数，用于从对象生成数据字典
     */
    public JSONObject serialize() throws JSONException {
        JSONObject json = new JSONObject();

        // 热词内容
        if(this.content != null) { json.put("content", this.content); }

        // 热词权重
        json.put("qz", this.qz);

        return json;
    }
}
